﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ProgramPSP0
{
    public class Numbers
    {
        List<int> listNum = new List<int>();
//ooooooooooooooooo
        public void ReadNumbers()
        {
            StreamReader sr = new StreamReader(@"C:\data.txt");
            string numStr;
            int num;
            while ((numStr = sr.ReadLine()) != null)
            {
                Console.Write(numStr + "  ");
                num = Convert.ToInt32(numStr);
                listNum.Add(num);
            }
            sr.Close();
        }

        public double Average()
        {
            double sum = 0;
            int n = listNum.Count();
            double average;
            for (int i = 0; i < n; i++)
            {
                sum += listNum[i];
            }
            average = sum / n;
            //Console.WriteLine("Average = " + average);
            return average;
        }

        public double StandardDivision()
        {
            double sum = 0;
            int length = listNum.Count();
            double everage = Average();
            double sd;

            for (int i = 0; i < length; i++)
            {
                double n = listNum[i] - everage;
                sum += Math.Pow(n, 2);
            }

            sd = Math.Sqrt(sum / length);
            //Console.WriteLine("Standard Division = " + sd);
            return sd;
        }

        public void BubbleSort()
        {
            int length = listNum.Count() - 1;
            int temp;

            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < length; j++)
                {
                    if (listNum[j + 1] < listNum[j])
                    {
                        temp = listNum[j + 1];
                        listNum[j + 1] = listNum[j];
                        listNum[j] = temp;
                    }
                }
            }

            for(int i = 0; i < length + 1; i++)
            {
                Console.Write(listNum[i] + " ");
            }
            Console.WriteLine();
        }

        public double Median()
        {
            int length = listNum.Count();
            int n = length % 2;
            int middleNum;
            double medianValue;

            if (n == 0)
            {
                middleNum = (length + 1) / 2;
                medianValue = (listNum[middleNum-1] + listNum[middleNum]);
                //Console.WriteLine("Median = " + (medianValue / 2) );
                return medianValue / 2;
            }
            else
            {
                middleNum = length / 2;
                medianValue = listNum[middleNum];
                //Console.WriteLine("Median = " + medianValue);
                return medianValue;
            }
        }

        public int Max()
        {
            int length = listNum.Count();
            int max = listNum[0];
            for (int i = 1; i < length; i++)
            {
                if (max < listNum[i])
                    max = listNum[i];
            }
            //Console.WriteLine("Max = " + max);
            return max;
        }

        public int Min()
        {
            int length = listNum.Count();
            int min = listNum[0];
            for (int i = 1; i < length; i++)
            {
                if (min > listNum[i])
                    min = listNum[i];
            }
            //Console.WriteLine("min = " + min);
            return min;
        }

        public double Skewness()
        {
            double average = Average();
            double sd = StandardDivision();
            int n = listNum.Count();
            double m2 = 0;
            double m3 = 0;
            double sum = 0;
            double skewness;

            for (int i = 0; i < n; i++)
            {
                double m = listNum[i] - average;
                sum += Math.Pow(n, 2);
            }
            m2 = sum / n;
            sum = 0;
            for (int i = 0; i < n; i++)
            {
                double m = listNum[i] - average;
                sum += Math.Pow(n, 3);
            }
            m3 = sum / n;
            skewness = m3 / (m2 * Math.Sqrt(m2));
            //Console.WriteLine("Skewness = " + skewness);
            return skewness;
        }

        public double Kurtosis()
        {

            double average = Average();
            double sd = StandardDivision();
            int n = listNum.Count();
            double m2 = 0;
            double m4 = 0;
            double sum = 0;
            double kurtosis;

            for (int i = 0; i < n; i++)
            {
                double m = listNum[i] - average;
                sum += Math.Pow(m, 2);
            }
            m2 = sum / n;
            sum = 0;
            for (int i = 0; i < n; i++)
            {
                double m = listNum[i] - average;
                sum += Math.Pow(m, 4);
            }
            m4 = sum / n;

            kurtosis = (m4 / (Math.Pow(m2, 2))) - 3;
            //Console.WriteLine("Kurtosis = " + kurtosis);
            return kurtosis;
        }
    }
}
